from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-03-30 14:14:04.013223
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 30, Mar, 2021
Time: 14:14:08
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.2023
Nobs: 246.000 HQIC: -47.9684
Log likelihood: 2912.10 FPE: 8.78029e-22
AIC: -48.4848 Det(Omega_mle): 6.13430e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.452071 0.128186 3.527 0.000
L1.Burgenland 0.070826 0.063339 1.118 0.263
L1.Kärnten -0.217636 0.054618 -3.985 0.000
L1.Niederösterreich 0.084164 0.140707 0.598 0.550
L1.Oberösterreich 0.221006 0.130930 1.688 0.091
L1.Salzburg 0.263886 0.070997 3.717 0.000
L1.Steiermark 0.137394 0.091756 1.497 0.134
L1.Tirol 0.115393 0.062251 1.854 0.064
L1.Vorarlberg -0.031241 0.057472 -0.544 0.587
L1.Wien -0.082258 0.117850 -0.698 0.485
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.485271 0.153275 3.166 0.002
L1.Burgenland 0.007077 0.075736 0.093 0.926
L1.Kärnten 0.338052 0.065308 5.176 0.000
L1.Niederösterreich 0.112912 0.168247 0.671 0.502
L1.Oberösterreich -0.077522 0.156555 -0.495 0.620
L1.Salzburg 0.213546 0.084893 2.515 0.012
L1.Steiermark 0.115217 0.109714 1.050 0.294
L1.Tirol 0.138062 0.074435 1.855 0.064
L1.Vorarlberg 0.155501 0.068720 2.263 0.024
L1.Wien -0.475618 0.140916 -3.375 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.304183 0.062456 4.870 0.000
L1.Burgenland 0.096672 0.030861 3.133 0.002
L1.Kärnten -0.015725 0.026611 -0.591 0.555
L1.Niederösterreich 0.049745 0.068557 0.726 0.468
L1.Oberösterreich 0.289671 0.063793 4.541 0.000
L1.Salzburg 0.016270 0.034592 0.470 0.638
L1.Steiermark 0.016952 0.044706 0.379 0.705
L1.Tirol 0.068173 0.030330 2.248 0.025
L1.Vorarlberg 0.083856 0.028002 2.995 0.003
L1.Wien 0.095945 0.057420 1.671 0.095
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.214916 0.063978 3.359 0.001
L1.Burgenland 0.021393 0.031613 0.677 0.499
L1.Kärnten 0.008517 0.027260 0.312 0.755
L1.Niederösterreich 0.048114 0.070227 0.685 0.493
L1.Oberösterreich 0.402036 0.065347 6.152 0.000
L1.Salzburg 0.082019 0.035435 2.315 0.021
L1.Steiermark 0.134771 0.045796 2.943 0.003
L1.Tirol 0.048543 0.031070 1.562 0.118
L1.Vorarlberg 0.082341 0.028684 2.871 0.004
L1.Wien -0.042547 0.058820 -0.723 0.469
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.519835 0.125129 4.154 0.000
L1.Burgenland 0.081460 0.061829 1.317 0.188
L1.Kärnten 0.009810 0.053316 0.184 0.854
L1.Niederösterreich -0.029341 0.137352 -0.214 0.831
L1.Oberösterreich 0.138469 0.127808 1.083 0.279
L1.Salzburg 0.054742 0.069305 0.790 0.430
L1.Steiermark 0.087862 0.089568 0.981 0.327
L1.Tirol 0.213361 0.060766 3.511 0.000
L1.Vorarlberg 0.030893 0.056101 0.551 0.582
L1.Wien -0.097767 0.115040 -0.850 0.395
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.202020 0.096997 2.083 0.037
L1.Burgenland -0.016655 0.047928 -0.347 0.728
L1.Kärnten -0.018302 0.041329 -0.443 0.658
L1.Niederösterreich -0.028377 0.106472 -0.267 0.790
L1.Oberösterreich 0.425892 0.099073 4.299 0.000
L1.Salzburg 0.007982 0.053723 0.149 0.882
L1.Steiermark -0.014651 0.069431 -0.211 0.833
L1.Tirol 0.161928 0.047104 3.438 0.001
L1.Vorarlberg 0.058036 0.043488 1.335 0.182
L1.Wien 0.228025 0.089176 2.557 0.011
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.248695 0.120861 2.058 0.040
L1.Burgenland 0.019034 0.059720 0.319 0.750
L1.Kärnten -0.063038 0.051497 -1.224 0.221
L1.Niederösterreich -0.058054 0.132667 -0.438 0.662
L1.Oberösterreich 0.014027 0.123448 0.114 0.910
L1.Salzburg 0.076114 0.066940 1.137 0.256
L1.Steiermark 0.337643 0.086513 3.903 0.000
L1.Tirol 0.456387 0.058694 7.776 0.000
L1.Vorarlberg 0.149075 0.054188 2.751 0.006
L1.Wien -0.174590 0.111116 -1.571 0.116
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.133803 0.142533 0.939 0.348
L1.Burgenland 0.050968 0.070429 0.724 0.469
L1.Kärnten -0.069443 0.060731 -1.143 0.253
L1.Niederösterreich 0.196187 0.156456 1.254 0.210
L1.Oberösterreich -0.009036 0.145584 -0.062 0.951
L1.Salzburg 0.205026 0.078944 2.597 0.009
L1.Steiermark 0.119954 0.102025 1.176 0.240
L1.Tirol 0.053678 0.069218 0.775 0.438
L1.Vorarlberg 0.101102 0.063904 1.582 0.114
L1.Wien 0.221401 0.131041 1.690 0.091
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.589940 0.077456 7.616 0.000
L1.Burgenland -0.039553 0.038273 -1.033 0.301
L1.Kärnten -0.025323 0.033003 -0.767 0.443
L1.Niederösterreich 0.011500 0.085022 0.135 0.892
L1.Oberösterreich 0.329952 0.079114 4.171 0.000
L1.Salzburg 0.018095 0.042900 0.422 0.673
L1.Steiermark -0.030526 0.055443 -0.551 0.582
L1.Tirol 0.087314 0.037615 2.321 0.020
L1.Vorarlberg 0.111995 0.034727 3.225 0.001
L1.Wien -0.044932 0.071211 -0.631 0.528
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.139740 0.036516 0.160526 0.217511 0.056735 0.077309 -0.002547 0.153410
Kärnten 0.139740 1.000000 0.019432 0.206472 0.179075 -0.064501 0.158538 0.023683 0.306052
Niederösterreich 0.036516 0.019432 1.000000 0.251243 0.067391 0.296472 0.139201 0.032286 0.305449
Oberösterreich 0.160526 0.206472 0.251243 1.000000 0.302150 0.280631 0.088035 0.060309 0.136083
Salzburg 0.217511 0.179075 0.067391 0.302150 1.000000 0.154079 0.048796 0.091249 -0.001832
Steiermark 0.056735 -0.064501 0.296472 0.280631 0.154079 1.000000 0.111244 0.098725 -0.122147
Tirol 0.077309 0.158538 0.139201 0.088035 0.048796 0.111244 1.000000 0.164902 0.145852
Vorarlberg -0.002547 0.023683 0.032286 0.060309 0.091249 0.098725 0.164902 1.000000 0.003046
Wien 0.153410 0.306052 0.305449 0.136083 -0.001832 -0.122147 0.145852 0.003046 1.000000